
#import "NSArray+Category.h"
#import <objc/runtime.h>
@implementation NSArray (Category)
+ (void)load{
    static dispatch_once_t onceDispatch;
    dispatch_once(&onceDispatch, ^{
        method_exchangeImplementations(class_getInstanceMethod(NSClassFromString(@"__NSArrayI"), NSSelectorFromString(@"objectAtIndex:")), class_getInstanceMethod(NSClassFromString(@"NSArray"), NSSelectorFromString(@"st_objectAtIndex:")));

        method_exchangeImplementations(class_getInstanceMethod(NSClassFromString(@"__NSPlaceholderArray"), NSSelectorFromString(@"initWithObjects:count:")), class_getInstanceMethod(NSClassFromString(@"NSArray"), NSSelectorFromString(@"initWithObjects_st:count:")));
       
        method_exchangeImplementations(class_getInstanceMethod(NSClassFromString(@"__NSArrayI"), NSSelectorFromString(@"arrayByAddingObject:")), class_getInstanceMethod(NSClassFromString(@"NSArray"), NSSelectorFromString(@"arrayByAddingObject_st:")));

    });
}
- (id)st_objectAtIndex:(NSUInteger)index{
    //判断数组是否越界
    if (index >= [self count]) {
        return nil;
    }
    return [self st_objectAtIndex:index];
}
- (NSArray *)arrayByAddingObject_st:(id)anObject {
    if (!anObject) {
        return self;
    }
    return [self arrayByAddingObject_st:anObject];
}
- (instancetype)initWithObjects_st:(id *)objects count:(NSUInteger)count {
    NSUInteger newCount = 0;
    for (NSUInteger i = 0; i < count; i++) {
        if (!objects[i]) {
            break;
        }
        newCount++;
    }
    self = [self initWithObjects_st:objects count:newCount];
    return self;
}

@end
